{{define "blog/ArticleType/edit.html"}} {{ template "header" . }}

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox-title">
            系统管理 / 帮助中心类别管理 / 编辑帮助中心类别
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-horizontal">
                            <input type="hidden" name="token" value="{{ .token }}">
                            <input type="hidden" name="id" value="{{ .data.ID }}">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">类别名称：</label>
                                <div class="col-sm-3">
                                    <input type="text" placeholder="" name="type_name" class="form-control" value="{{.data.TypeName}}" required> <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序：</label>
                                <div class="col-sm-3">
                                    <input type="number" placeholder="" name="sort_num" class="form-control" required max="99999" value="{{.data.SortNum}}"> <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">语言类型：</label>
                                <div class="col-sm-3">
                                    <input type="radio" id="chn" name="lang_type" class="custom-control-input" value="1" {{if eq .data.LangType 1}} checked {{end}}>
                                    <label class="custom-control-label" for="chn">中文</label>
                                    <input type="radio" id="eng" name="lang_type" class="custom-control-input" value="2" {{if eq .data.LangType 2}} checked {{end}}>
                                    <label class="custom-control-label" for="eng">英语</label>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-3">
                                    <button class="btn btn-sm btn-primary" onclick="add()">添 加</button>
                                    <a href="/blog/articletype" class="btn btn-sm btn-white">取消</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

{{ template "footer" . }}
<script>
    function add() {
        let token = $("input[name='token']").val();
        let id = $("input[name='id']").val();
        let type_name = $("input[name='type_name']").val();
        let sort_num = $("input[name='sort_num']").val();
        let lang_type = $("input[name='lang_type']:checked").val();
        let prompt_msg = "";
        console.log("length", type_name.length)
        if (type_name === "" || type_name.length < 3 || type_name.length > 50) {
            prompt_msg = "请输入3~50个字符的分类名称";
        }
        if (prompt_msg !== "") {
            layer.msg(prompt_msg, {
                icon: 2,
                time: 1200,
                title: "提示"
            });
            return;
        }

        $.post("/blog/articletype/edit", {
            type_name,
            token,
            sort_num,
            lang_type,
            id
        }, function(jsonData) {
            // var jsonData = $.parseJSON(res);
            if (jsonData.status !== 200 && jsonData.status !== 20023) {
                if (jsonData.status !== 20007) {
                    $("input[name='token']").val(jsonData.data);
                }
                layer.msg(jsonData.message, {
                    icon: 2,
                    time: 1200,
                    title: "提示"
                });
            } else if (jsonData.status === 20023) {
                window.location.href = "/nopermission";
            } else {
                layer.msg(jsonData.message, {
                    icon: 1,
                    time: 1000,
                    title: "提示",
                    end: function() {
                        window.location.href = "/blog/articletype";
                    }
                });
            }
        });
    }
</script>
{{end}}